import sys

import cv2     # opencv-python==4.2.0.34
import os
#import numpy as np    #numpy==1.21.6

mainFolder = r'D:\data\CUGW-test\20230810left3'
# 遍历images文件夹下的所有文件夹
myFiles = os.listdir(mainFolder)
# 输出所有子文件（夹）的名称
print(myFiles)

images = []
# 读取每张图片
for imgName in myFiles:
    if(os.path.isdir(mainFolder+'/'+imgName) or imgName.endswith(".txt")):
        continue
    curImg = cv2.imread(f'{mainFolder}/{imgName}')
    #curImg = cv2.resize(curImg,(0,0),None,0.2,0.2)  # 重新设置图片大小
    images.append(curImg)
    imgExt = os.path.splitext(imgName)[-1]
if(len(images)==0):
    print('images is empty')
    sys.exit()
stitcher = cv2.Stitcher.create()  # 创建一个stitcher实例，cv2.Stitcher.SCANS
(status, result) = stitcher.stitch(images)   
if (status == 0):       # 状态码为0的时候，进行处理
	print('Panorma Generated')
	print(imgExt)
	cv2.imwrite(mainFolder + imgExt,result)
	cv2.imshow(mainFolder + imgExt, result)#cv2.WND_PROP_FULLSCREEN
else:
	print('Panorma Generated Unsuccessful,error code='+str(status))
cv2.waitKey(0)